package vn.edu.saigontech.ncms.model.bookstore;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.model.system.Money;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_bookstore_order_detail")
@SuppressWarnings("serial")
public class OrderDetail extends BaseEntity {
	
	@ManyToOne
	@JoinColumn(name = "item_id")
	private Item item;

	@Embedded
	@AttributeOverrides( {
			@AttributeOverride(name = "amount", column = @Column(name = "price_detail")),
			@AttributeOverride(name = "currency", column = @Column(name = "price_detail_currency")), })
	private Money priceDetail;

	@Column(name = "quantity")
	private int quantity;

	@ManyToOne
	@JoinColumn(name = "order_id")
	private Order order;
	
	public double getTotalPrice() {
		return this.priceDetail.getAmount() * quantity;
	}

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public Money getPriceDetail() {
		return priceDetail;
	}

	public void setPriceDetail(Money priceDetail) {
		this.priceDetail = priceDetail;
	}
}